<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
echo "<h2>Покупатели</h2>";
$this->table->set_heading('id', 'e-mail', 'Имя', 'Статус', 'Группа', 'Действия');
$tmpl = array('table_open' => '<table border="0" cellpadding="0" cellspacing="0" class="admin_table">');
$this->table->set_template($tmpl);

$class = 'clients';
if ($this->users_rights_model->check_rights($class, 'block', true)) $canblock = 1;
if ($this->users_rights_model->check_rights($class, 'unblock', true)) $canblock = 1;
if ($this->users_rights_model->check_rights($class, 'edit', true)) $canedit = 1;
if ($this->users_rights_model->check_rights($class, 'delete', true)) $candelete = 1;
if ($this->users_rights_model->check_rights($class, 'add', true)) $canadd = 1;
?>
<? if ($this->input->server('REQUEST_METHOD') != "POST") { ?>
	<div class="filter">
		<a href="/admin/<?=$class?>/?from=<?=$from?>" <?=($this->input->get('active') === false?"class='active'":"")?>>Все</a>
		<a href="/admin/<?=$class?>/?from=<?=$from?>&active=1" <?=($this->input->get('active') == 1?"class='active'":"")?>>Только активные</a>
		<a href="/admin/<?=$class?>/?from=<?=$from?>&active=0" <?=($this->input->get('active') === "0"?"class='active'":"")?>>Только неактивные</a>
	</div>
<? } ?>
	<div class="filter">
		<form action="/admin/<?=$class?>/" method="post">
			Искать покупателя по имени, email или идентификатору: <input type='text' name='text' value="<?=$this->input->post('text')?>" /> <input type='submit' value='Найти' /> 
			<? if ($this->input->server('REQUEST_METHOD') == "POST") { ?>
			<a href='/admin/<?=$class?>/'>Очистить фильтр</a>
			<? } ?>
		</form>
	</div>
<?

foreach ($pages as $page) {
$oid = $page['id'];

			if ($this->input->post('text') != "") {
				$s_text = explode(" ",$this->input->post('text'));

				foreach ($s_text as $s_seg) {
					$s_seg = trim($s_seg);
					if ($s_seg != "") {
						$page['email'] = preg_replace("/(".$s_seg.")/iu", "<b style='color: red;'>$1</b>", $page['email']);
						$page['first_name'] = preg_replace("/(".$s_seg.")/iu", "<b style='color: red;'>$1</b>", $page['first_name']);
						$page['id'] = preg_replace("/(".$s_seg.")/iu", "<b style='color: red;'>$1</b>", $page['id']);
					}
				}
			}

	$this->table->add_row(
			$page['id'],
			"<a href='/admin/".$class."/edit/".$oid."/'>".$page['email']."</a>",
			$page['first_name'],
			($page['active']==1?"Активен":"Не активен"),
			$groups[$page['group_id']]['description'],
			showmeactions(
					$class,
					$oid,
					$page['active'],
					$canedit, $candelete, 0,
					$from
				)
		);
}
echo $this->table->generate();
echo $paging;
if ($canadd == 1) {
//	echo showmeadd($class, 'Добавить пользователя');
}
echo "<div class='cc'></div>";
?>
